#include "drv_systick.h"

static uint32_t fs_us=0;//unit8_t:0~255 unit16:0~65535 unit32:0~4294967295
static uint32_t fs_ms=0;
void drv_systick_init(uint32_t systick)//SysTick定时器(滴答定时器)重置
{
	SysTick->CTRL &= ~0x05;
	fs_us=systick/8;
	fs_ms=fs_us*1000;
}

void drv_systick_ms(uint32_t ms)
{
	while(ms>798)
	{
		drv_systick_ms(798);//该值必须不满足循环条件，否则程序崩溃
		ms -=798;
	}
	if(0<ms<=798)
	{
	uint32_t temp;
	SysTick->LOAD =fs_ms*ms;
	SysTick->CTRL |=0x01;
		do
		{
			temp=SysTick->CTRL;
		}
		while(!(temp&(0x01<<16)));
	}
}
void drv_systick_us(uint32_t us)
{
	while(us>798)
	{
		drv_systick_us(798);
		us -=798;
	}
	if(0<us<=798)
	{
	uint32_t temp;
	SysTick->LOAD =fs_us*us;
	SysTick->CTRL |=0x01;
		do
		{
			temp=SysTick->CTRL;
		}
		while(!(temp&(0x01<<16)));
	}
}

